package com.marmot.cloud.framework.orm.jpa.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.marmot.cloud.framework.orm.jpa.comment.annotation.Comment;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Data
@MappedSuperclass
@EqualsAndHashCode(callSuper=true)
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseJpaEntity extends BaseEntity {

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "org.hibernate.id.UUIDGenerator")
    @Column(length = 36)
    @Comment(value = "主键")
    public String id;

    @Column(length = 36)
    @Comment(value = "创建者ID")
    protected String createBy;

    @CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column
    @Comment(value = "创建时间")
    protected LocalDateTime createdAt;

    @Column(length = 36)
    @Comment(value = "最后修改人ID")
    protected String updateBy;

    @LastModifiedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column
    @Comment(value = "最后修改时间")
    protected LocalDateTime updatedAt;

    @Column(length = 1)
    @Comment(value = "删除标记:0=未删除,1=删除")
    protected Integer deleted;

    @Version
    @Column
    @Comment(value = "版本号")
    protected Long version;

}
